import 'dart:ffi';

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:ymApp/common/http_service.dart';
import 'package:ymApp/extension/int_extendion.dart';
import 'package:ymApp/model/video_model.dart';
import 'package:ymApp/router/routes.dart';

import '../../public.dart';

class GridItem extends StatefulWidget {
  VideoModel item;

  GridItem(this.item);

  @override
  _GridItemState createState() => _GridItemState();
}

class _GridItemState extends State<GridItem> {
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        Routes.navigateTo(context, Routes.indexDetail);
      },
      child: Container(
        decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.all(Radius.circular(10)),
            boxShadow: [
              BoxShadow(
                  color: Colors.black12, offset: Offset(0, 2), blurRadius: 10)
            ]),
        child: Column(
          children: [
            Container(
              decoration: BoxDecoration(
                borderRadius: BorderRadius.all(Radius.circular(10)),
              ),
              child: Stack(
                overflow: Overflow.clip,
                children: [
                  AspectRatio(
                      aspectRatio: 200 / 125,
                      child: ClipRRect(
                        borderRadius: BorderRadius.only(
                            topLeft: Radius.circular(10),
                            topRight: Radius.circular(10)),
                        child: Image.network(
                          widget.item.posterUrl,
                          fit: BoxFit.cover,
                        ),
                      )),
                  Positioned(
                    left: 0,
                    bottom: 0,
                    right: 0,
                    child: Container(
                      height: 40.rpx,
                      color: Colors.black12,
                      child: DefaultTextStyle(
                        style: TextStyle(color: Colors.white, fontSize: 20.rpx),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            Row(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                SizedBox(
                                  width: 15.rpx,
                                ),
                                Icon(
                                  Icons.ondemand_video,
                                  color: Colors.white,
                                ),
                                SizedBox(
                                  width: 10.rpx,
                                ),
                                Text('31.5万'),
                                SizedBox(
                                  width: 20.rpx,
                                ),
                                Icon(
                                  Icons.receipt,
                                  color: Colors.white,
                                ),
                                SizedBox(
                                  width: 10.rpx,
                                ),
                                Text('31.5万')
                              ],
                            ),
                            Padding(
                              padding:
                                  EdgeInsets.only(right: 15.rpx, top: 4.rpx),
                              child: Text('4:00'),
                            )
                          ],
                        ),
                      ),
                    ),
                  )
                ],
              ),
            ),
            Expanded(
              child: Container(
                width: double.infinity,
                padding: EdgeInsets.symmetric(horizontal: 15.rpx),
                child: Stack(
                  children: [
                    Text(
                      widget.item.title,
                      style: TextStyle(fontSize: 26.rpx),
                      maxLines: 2,
                      overflow: TextOverflow.ellipsis,
                    ),
                    Positioned(
                      bottom: 8.rpx,
                      left: 0,
                      right: 0,
                      child: Container(
                        height: 50.rpx,
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text(
                              '搞笑 · 大帅锅',
                              style: TextStyle(fontSize: 22.rpx),
                            ),
                            IconButton(
                              color: Colors.red,
                              icon: Icon(Icons.more_vert),
                              onPressed: () {
//                                 _showBottomSheet();
                                BotToast.showText(text: "文本框提示！"); //弹出一个文本框;
//                              BotToast.showSimpleNotification(title: "init"); //弹出简单通知Toast
                                //弹出一个定位Toast
//                                BotToast.showAttachedWidget(
//                                    attachedBuilder: (_) => Card(
//                                      child: Padding(
//                                        padding: const EdgeInsets.all(8.0),
//                                        child: Icon(
//                                          Icons.favorite,
//                                          color: Colors.redAccent,
//                                        ),
//                                      ),
//                                    ),
//                                    duration: Duration(seconds: 2),
//                                    target: Offset(520, 520));
//                                print('点击了');
                              },
                            )
                          ],
                        ),
                      ),
                    )
                  ],
                ),
              ),
            )
          ],
        ),
      ),
    );
  }

  void _showBottomSheet() {
    showModalBottomSheet(
        backgroundColor: Colors.transparent,
        context: context,
        builder: (context) {
          return Stack(
            children: [
              Container(
                  padding: EdgeInsets.all(30.rpx),
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.only(
                          topLeft: Radius.circular(20),
                          topRight: Radius.circular(20)),
                      color: Colors.white),
                  height: double.infinity,
                  child: ListView(
                    children: List.generate(50, (index) {
                      return Text('data');
                    }),
                  )),
              Positioned(
                width: 60.rpx,
                height: 60.rpx,
                right: 10.rpx,
                top: 10.rpx,
                child: GestureDetector(
                  child: Icon(
                    Icons.close,
                    size: 40.rpx,
                  ),
                  onTap: () {
                    Navigator.pop(context);
                  },
                ),
              ),
            ],
          );
        });
  }
}
